1. /* sdfcbrt.cpp by K.Tsuru */
  2. // function ID 3010 DRADIX only
  3. /***************************
  4. SDouble class
  5. cubic root of a
  6. It returns a*RecCbrt(a*a).
  7. ****************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. static const char* const func = "Cbrt";
  12. SDouble Cbrt(const SDouble& a){
  13. SDouble d, y;
  14. //When 'a' is a short number including |a| = 1.0 or 0.0
  15. //It costs a little time bacause the "db" is a short number.
  16. uint xfig = a.Last() - a.First();
  17. if(xfig < 4){
  18. SDouble db;
  19. y.SNError(); //reset error
  20. db = pow( fabs(doubleD(a, 0)), 1.0/3.0);
  21. if(y.SNError()==y.NO_ERR){ //detect an error in doubleD()
  22. if(a.Sign(3010)<0) db.ChangeSign();
  23. y = a - db*(db*db);
  24. if(y.Sign(3007)== 0) return db;
  25. }
  26. }
  27. y = a*a;
  28. y = a*RecCbrt(y);
  29. /**************************************************
  30. It adds a correction. Maybe this is not necessary.
  31. Let d = a - y'^3
  32. y = a^(1/3) =(y'^3+d)^(1/3) = y'{1+d/(y'^3)}^(1/3)
  33. = y' + d/{3*(y'^2)}+...
  34. ****************************************************/
  35. #if 0
  36. if(y.PreferSpeed() == OFF){
  37. SDouble y2;
  38. y2 = y*y; d = a - y2*y;
  39. if(d.Sign()){
  40. d = d/y2;
  41. y += DsDiv(d, 3);
  42. }
  43. }
  44. #endif
  45. if(y.Verify()){ // check |a - y^3| << a ?
  46. d = a - (y*y)*y;
  47. if(!d.IsMLT(a)){ //It sees the relative error. d << a ?
  48. y.SetError(y.VERIFY, func, 3010);
  49. }
  50. }
  51. return y;
  52. }

sdfcbrt.cpp : last modifiled at 2016/07/06 16:19:06(1,375 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).